// Package utildownload contains internal helper functions utilized by the
// primary mobsql app logic.
package utilfuncs

func ArrayWithValue[T any](size int, s T) []T {
	r := make([]T, size)
	for i := range r {
		r[i] = s
	}
	return r
}

func ColonPrefixItems(items []string) []string {
	r := []string{}
	for _, s := range items {
		r = append(r, ":"+s)
	}
	return r
}

func ItemInArray[T comparable](item T, items []T) bool {
	for _, s := range items {
		if item == s {
			return true
		}
	}
	return false
}

func MapKeys[T comparable](m map[T]any) []T {
	keys := []T{}
	for k, _ := range m {
		keys = append(keys, k)
	}
	return keys
}

func Anyify[T any](items []T) []any {
	r := []any{}
	for _, item := range items {
		r = append(r, any(item))
	}
	return r
}

func Pairs[T any](items []T) [][]T {
	pairs := [][]T{}
	for _, s1 := range items {
		for _, s2 := range items {
			pairs = append(pairs, []T{s1, s2})
		}
	}
	return pairs
}

func IntArraysSortedFilter(intArrays [][]int) [][]int {
	r := [][]int{}
OUTER:
	for _, items := range intArrays {
		last := -99999
		for _, item := range items {
			if item < last {
				continue OUTER
			} else {
				last = item
			}
		}
		r = append(r, items)
	}
	return r
}
